<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once ('PrunusTable.php');
require_once ('PrunusRelation.php');

class PrunusTblRoles extends PrunusTable {
  public function __construct() {
    $columns = array ('rol_id'     => array('flags'=>'lg')
                     ,'rol_name'   => array('flags'=>'lgiu')
                     ,'rol_builtin'=> array('flags'=>' giu')
                     ,'rol_alive'  => array('flags'=>' gi')
                     );
    parent::__construct('pr_roles', $columns, 'rol_id','rol_alive');
    
    $columnsTranslateRelation1M = array ('roltrn_id'    => array('flags'=>'l')
                                        ,'roltrn_lng'   => array('flags'=>'li', 'parent'=>array('tableName'=>'pr_languages', 'idColumnName'=>'lng_id', 'nameColumnName'=>'lng_code', 'aliveColumnName'=>'lng_alive', 'duplicates' => FALSE ))
                                        ,'roltrn_rol'   => array('flags'=>'l')
                                        ,'roltrn_name'  => array('flags'=>'li')
                                        ,'roltrn_alive' => array('flags'=>'li')
                                      );
    $relTranslate = new PrunusRelation('pr_roles_translate', 'roltrn_id', 'roltrn_alive', 'roltrn_rol', $this, $columnsTranslateRelation1M);
    parent::addRelation('translate', $relTranslate);

    $columnsUsuarioRelationMM = array ('usurol_id'    => array('flags'=>'l')
                                      ,'usurol_usu'   => array('flags'=>'li', 'parent'=>array('tableName'=>'pr_usuarios', 'idColumnName'=>'usu_id', 'nameColumnName'=>'usu_name', 'aliveColumnName'=>'usu_alive', 'duplicates' => FALSE ))
                                      ,'usurol_rol'   => array('flags'=>'l')
                                      );
    $relUsuarios = new PrunusRelation('pr_usuarios_roles', 'usurol_id', null, 'usurol_rol', $this, $columnsUsuarioRelationMM);
    parent::addRelation('usuarios', $relUsuarios);
    
    $columnsPermisosRelation = array ('per_id'      => array('flags'=>'l')
                                     ,'per_usu'     => array('flags'=>'l', 'value' => 0)
                                     ,'per_rol'     => array('flags'=>'l')
                                     ,'per_pag'     => array('flags'=>'li', 'parent'=>array('tableName'=>'pr_pages', 'idColumnName'=>'pag_id', 'nameColumnName'=>'pag_identifier', 'aliveColumnName'=>'pag_alive', 'duplicates' => FALSE, 'optionalValue' => 0 ))
                                     ,'per_permiso' => array('flags'=>'li')
                                     );
    $relPermisos = new PrunusRelation('pr_permisos', 'per_id', null, 'per_rol', $this, $columnsPermisosRelation);
    parent::addRelation('permisos', $relPermisos);
    
  }
}
